/*!
 * mars
 * Copyright(c) 2015 huangbinglong
 * MIT Licensed
 */

'use strict';

angular.module("ckApp", [])
    .controller("ckIndexController", function ($scope,ckAppMaster) {
        var vm = this;

        vm.title = "AdminLTE+Angular";

        ckAppMaster.init(vm);
    })
    .factory("ckAppMaster", function () {
        var factory = {};
        factory.init = function (appCtrl) {
            if (this._appCtrl) {
                throw new Error("已经初始化过了！");
            }
            this._appCtrl = appCtrl;
        };
        factory.getMaster = function () {
            return this._appCtrl;
        };
        return factory;
    })
    .directive("ckResizeIframe", function () {
        return {
            restrict: "A",
            replace: false,
            template: "",
            link: function (scope, element, attrs) {
                // iframe加载时，重新适配iframe大小
                $(element[0]).load(function () {
                    element[0].style.height = element[0].contentWindow.document.body.scrollHeight + "px";
                    // 点击iframe时，触发父窗口点击事件
                    $(element[0].contentWindow.document.body).click(function () {
                        element[0].contentWindow.parent.document.body.click();
                    });
                });
            }
        };
    });